package com.tedu.ds.role.controller;

import com.tedu.ds.base.response.JsonResult;
import com.tedu.ds.role.pojo.dto.RoleParam;
import com.tedu.ds.role.pojo.dto.RoleQuery;
import com.tedu.ds.role.service.RoleService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/v1/role")
@Api(tags = "角色模块")
public class RoleController {
    @Autowired
    private RoleService roleService;

    @PostMapping("/select")
    @ApiOperation("查询功能")
    public JsonResult select(@RequestBody RoleQuery roleQuery){
        return JsonResult.ok(roleService.select(roleQuery));
    }

    @PostMapping("/save")
    @ApiOperation("新增和更新功能")
    public JsonResult save(@RequestBody @Validated RoleParam roleParam){
        roleService.save(roleParam);
        return JsonResult.ok();
    }

    @DeleteMapping("/delete/{id}")
    @ApiOperation("删除功能")
    public JsonResult deleteById(@PathVariable Integer id){
        roleService.deleteById(id);
        return JsonResult.ok();
    }
}
